n = int(input())
p = int(input())
s = int(5 ** (1 / 2))
print(int((1/s)*(((((1+s))/2)** n) - ((((1-s) / 2) ** n)) + 0.5) % p))
